// Bristleback plugin - Copyright (c) 2010 bristleback.googlecode.com
// ---------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
// This library is distributed in the hope that it will be useful,
// but without any warranty; without even the implied warranty of merchantability
// or fitness for a particular purpose.
// You should have received a copy of the GNU Lesser General Public License along
// with this program; if not, see <http://www.gnu.org/licenses/lgpl.html>.
package pl.bristleback.server.bristle;

import org.apache.log4j.Logger;
import org.jwebsocket.factory.JWebSocketFactory;
import pl.bristleback.server.bristle.utils.JWebSocketResource;

/**
 * Class used to start JWebsocket server.
 * Basically it's a wrapper for JWebSocketFactory that simplifies setting location of jwebsocket.xml file.
 * You can start server with default location of the file from classpath or with given absolute path.
 * <p/>
 * Created on: 04.06.11 13:00 <br/>
 *
 * @author Paweł Machowski
 */
public class Bristleback {
  private static Logger log = Logger.getLogger(Bristleback.class.getName());

  public static final String JWEBSOCKET_FILENAME = "jwebsocket.xml";

  /**
   * Starts JWebSocket server.
   * Configuration file location is taken from classpath.
   * Default file name is "jwebsocket.xml"
   * If you want to specify own config location use method start(String absoluteFileName)
   */
  public void start() {
    JWebSocketResource configFile = new JWebSocketResource(JWEBSOCKET_FILENAME);
    JWebSocketFactory.start(configFile.getAbsoluteFilePath());
  }

  /**
   * Starts JWebSocket server with given configuration file.
   * Path to configuration file must be given as absolute path.
   * You can customize action on server start by
   * setting own implementation of ServerStateListener interface in jwebsocket.xml.
   *
   * @param absoluteFileName absolute path to configuration file
   */
  public void start(String absoluteFileName) {
    JWebSocketFactory.start(absoluteFileName);
  }

  /**
   * Stops JWebSocket server.
   * You can customize action on server stop by
   * setting own implementation of ServerStateListener interface in jwebsocket.xml.
   */
  public void stop() {
    JWebSocketFactory.stop();
  }

} 